"""
添加用户类
"""

from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select


class AddUserPage(BasePage):
    user_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/div[2]/div[2]/form/table/tbody/tr[1]/td[2]/input')
    passwords_locator = (By.CSS_SELECTOR, "#password")
    classes_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/div[2]/div[2]/form/table/tbody/tr[3]/td[2]/select')
    department_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/div[2]/div[2]/form/table/tbody/tr[4]/td[2]/select')
    post_locator = (By.XPATH, '//*[@id="role2"]')
    add_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/div[2]/div[2]/form/table/tbody/tr[6]/td[2]/input[1]')

    def input_user(self,user):
        """输入用户名"""
        self.driver.find_element(*self.user_locator).send_keys(user)

    def input_passwords(self,passwords):
        """输入密码"""
        self.driver.find_element(*self.passwords_locator).send_keys(passwords)

    def choice_user_classes(self):
        """选择用户类别"""
        classes_element=self.driver.find_element(*self.classes_locator)
        select=Select(classes_element)
        select.select_by_index(1)

    def choice_department(self):
        """选择部门"""
        department_element=self.driver.find_element(*self.department_locator)
        select=Select(department_element)
        select.select_by_index(1)

    def choice_post(self):
        """选择岗位"""
        post_element=self.driver.find_element(*self.post_locator)
        select=Select(post_element)
        select.select_by_index(0)

    def click_add_btn(self):
        """点击添加按钮"""
        self.driver.find_element(*self.add_locator).click()

